var topKFrequent = function(nums, k) {
    let map = new Map()
    const n = nums.length;
    let res = [];
    for(let i = 0; i < n; i++) {
        if(map.has(nums[i])) {
            map.set(nums[i],map.get(nums[i]) + 1)
        }
        else {
            map.set(nums[i],1);
        }
    }
    console.log(map)
    map = Array.from(map);
    map.sort((a,b) =>b[1]-a[1]);
    map = map.splice(0,k)
    map.forEach(item => res.push(item[0]))
    return res
};
console.log(topKFrequent([5,3,1,1,1,3,73,1],1))